package com.darkplanet.management.controller;

import com.darkplanet.management.domain.Project;
import com.darkplanet.management.domain.SecondMenu;
import com.darkplanet.management.service.ProjectService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

@WebServlet("/ProjectBaseServlet")
public class ProjectBaseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        if(session.getAttribute("employee")!=null){
            List menus1 = (List) session.getAttribute("Menus");
            List<SecondMenu> menuList = (List<SecondMenu>) menus1.get(1);
            for (SecondMenu secondMenu : menuList) {
                if(secondMenu.getS_menu_id()==13){
        ProjectService projectService = new ProjectService();
        List<Project> allProject = projectService.getAllProject();
        session.setAttribute("allProject",allProject);

        response.sendRedirect(request.getContextPath()+"/project-base.jsp");
    }
            }
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
